const methods = require('./methods.js')

const host = 'https://zjj-adjust.yeekin.cn';
const http = async (url = '', data = {}, type = 'GET', isShowLoading = false) => {
const app = getApp()
let token = app.globalData.token || '';
  let platform = 2;
  if (isShowLoading) {
    methods.showLoading()
  }
  return await new Promise((resolve, reject) => {
    wx.request({
      url: host + url,
      method: type,
      data: data,
      header: {
        'content-type': 'application/x-www-form-urlencoded',
        'Authorization':'Bearer ' + token
      },
      success: res => {
        //接口访问正常返回数据
        if (res.statusCode == 200) {
          resolve(res.data)
        } else {
          reject(res)
        }
      },
      fail: res => {
        methods.showToast('网络连接超时')
        reject(res)
      },
      complete: res => {
        if (isShowLoading) {
          methods.hideLoading()
        }
      }
    })
  })
}
export default http